package com.hmall.api.item;

import com.hmall.api.item.dto.ItemDTO;
import com.hmall.api.item.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.asn1.esf.SigPolicyQualifierInfo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * itemClient的通用降级策略
 *
 * @author makangkang
 * @date 2025/11/10 10:13
 */
@Slf4j
@Component
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                // 打印异常信息
                log.error("[远程调用ItemClient的queryItemByIds方法出现异常，参数为；{}]", ids, cause);
                cause.printStackTrace();
                return Collections.emptyList();
            }


            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                // 打印异常信息
                log.error("[远程调用ItemClient的deductStock方法出现异常，参数为；{}]", items, cause);
                cause.printStackTrace();
            }
        };
    }
}
